<template>
  <el-dialog
    :title="!dataForm.memberId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="昵称ID" prop="docNick">
      <el-input v-model="dataForm.docNick" placeholder="昵称ID"></el-input>
    </el-form-item>
    <el-form-item label="医生头像" prop="docImg">
      <el-input v-model="dataForm.docImg" placeholder="医生头像"></el-input>
    </el-form-item>
    <el-form-item label="医师编号" prop="docId">
      <el-input v-model="dataForm.docId" placeholder="医师编号"></el-input>
    </el-form-item>
    <el-form-item label="医师姓名" prop="docName">
      <el-input v-model="dataForm.docName" placeholder="医师姓名"></el-input>
    </el-form-item>
    <el-form-item label="隶属医院" prop="hosName">
      <el-input v-model="dataForm.hosName" placeholder="隶属医院"></el-input>
    </el-form-item>
    <el-form-item label="科室" prop="departName">
      <el-input v-model="dataForm.departName" placeholder="科室"></el-input>
    </el-form-item>
    <el-form-item label="医师等级" prop="typeName">
      <el-input v-model="dataForm.typeName" placeholder="医师等级"></el-input>
    </el-form-item>
    <el-form-item label="手机号" prop="phone">
      <el-input v-model="dataForm.phone" placeholder="手机号"></el-input>
    </el-form-item>
    <el-form-item label="身份证号" prop="idNumber">
      <el-input v-model="dataForm.idNumber" placeholder="身份证号"></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="password">
      <el-input v-model="dataForm.password" placeholder="密码"></el-input>
    </el-form-item>
    <el-form-item label="年限" prop="docYear">
      <el-input v-model="dataForm.docYear" placeholder="年限"></el-input>
    </el-form-item>
    <el-form-item label="身份证正面" prop="numberImg">
      <el-input v-model="dataForm.numberImg" placeholder="身份证正面"></el-input>
    </el-form-item>
    <el-form-item label="医师资格证书" prop="docStatus">
      <el-input v-model="dataForm.docStatus" placeholder="医师资格证书"></el-input>
    </el-form-item>
    <el-form-item label="医师执行证书" prop="docPractice">
      <el-input v-model="dataForm.docPractice" placeholder="医师执行证书"></el-input>
    </el-form-item>
    <el-form-item label="审核状态，0未审核，1通过，2未通过" prop="auditState">
      <el-input v-model="dataForm.auditState" placeholder="审核状态，0未审核，1通过，2未通过"></el-input>
    </el-form-item>
    <el-form-item label="审核不通过原因" prop="auditnotCause">
      <el-input v-model="dataForm.auditnotCause" placeholder="审核不通过原因"></el-input>
    </el-form-item>
    <el-form-item label="我的余额" prop="docBalance">
      <el-input v-model="dataForm.docBalance" placeholder="我的余额"></el-input>
    </el-form-item>
    <el-form-item label="问诊次数" prop="askCount">
      <el-input v-model="dataForm.askCount" placeholder="问诊次数"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          memberId: 0,
          docNick: '',
          docImg: '',
          docId: '',
          docName: '',
          hosName: '',
          departName: '',
          typeName: '',
          phone: '',
          idNumber: '',
          password: '',
          docYear: '',
          numberImg: '',
          docStatus: '',
          docPractice: '',
          auditState: '',
          auditnotCause: '',
          docBalance: '',
          askCount: ''
        },
        dataRule: {
          docNick: [
            { required: true, message: '昵称ID不能为空', trigger: 'blur' }
          ],
          docImg: [
            { required: true, message: '医生头像不能为空', trigger: 'blur' }
          ],
          docId: [
            { required: true, message: '医师编号不能为空', trigger: 'blur' }
          ],
          docName: [
            { required: true, message: '医师姓名不能为空', trigger: 'blur' }
          ],
          hosName: [
            { required: true, message: '隶属医院不能为空', trigger: 'blur' }
          ],
          departName: [
            { required: true, message: '科室不能为空', trigger: 'blur' }
          ],
          typeName: [
            { required: true, message: '医师等级不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '手机号不能为空', trigger: 'blur' }
          ],
          idNumber: [
            { required: true, message: '身份证号不能为空', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '密码不能为空', trigger: 'blur' }
          ],
          docYear: [
            { required: true, message: '年限不能为空', trigger: 'blur' }
          ],
          numberImg: [
            { required: true, message: '身份证正面不能为空', trigger: 'blur' }
          ],
          docStatus: [
            { required: true, message: '医师资格证书不能为空', trigger: 'blur' }
          ],
          docPractice: [
            { required: true, message: '医师执行证书不能为空', trigger: 'blur' }
          ],
          auditState: [
            { required: true, message: '审核状态，0未审核，1通过，2未通过不能为空', trigger: 'blur' }
          ],
          auditnotCause: [
            { required: true, message: '审核不通过原因不能为空', trigger: 'blur' }
          ],
          docBalance: [
            { required: true, message: '我的余额不能为空', trigger: 'blur' }
          ],
          askCount: [
            { required: true, message: '问诊次数不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.memberId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.memberId) {
            this.$http({
              url: this.$http.adornUrl(`/aftersystem/member/info/${this.dataForm.memberId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.docNick = data.member.docNick
                this.dataForm.docImg = data.member.docImg
                this.dataForm.docId = data.member.docId
                this.dataForm.docName = data.member.docName
                this.dataForm.hosName = data.member.hosName
                this.dataForm.departName = data.member.departName
                this.dataForm.typeName = data.member.typeName
                this.dataForm.phone = data.member.phone
                this.dataForm.idNumber = data.member.idNumber
                this.dataForm.password = data.member.password
                this.dataForm.docYear = data.member.docYear
                this.dataForm.numberImg = data.member.numberImg
                this.dataForm.docStatus = data.member.docStatus
                this.dataForm.docPractice = data.member.docPractice
                this.dataForm.auditState = data.member.auditState
                this.dataForm.auditnotCause = data.member.auditnotCause
                this.dataForm.docBalance = data.member.docBalance
                this.dataForm.askCount = data.member.askCount
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/aftersystem/member/${!this.dataForm.memberId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'memberId': this.dataForm.memberId || undefined,
                'docNick': this.dataForm.docNick,
                'docImg': this.dataForm.docImg,
                'docId': this.dataForm.docId,
                'docName': this.dataForm.docName,
                'hosName': this.dataForm.hosName,
                'departName': this.dataForm.departName,
                'typeName': this.dataForm.typeName,
                'phone': this.dataForm.phone,
                'idNumber': this.dataForm.idNumber,
                'password': this.dataForm.password,
                'docYear': this.dataForm.docYear,
                'numberImg': this.dataForm.numberImg,
                'docStatus': this.dataForm.docStatus,
                'docPractice': this.dataForm.docPractice,
                'auditState': this.dataForm.auditState,
                'auditnotCause': this.dataForm.auditnotCause,
                'docBalance': this.dataForm.docBalance,
                'askCount': this.dataForm.askCount
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
